package com.etone.smartFlow.service.impl;

import com.etone.smartAudit.commService.CommPUumOrganizationinfoService;
import com.etone.smartAudit.commService.CommPUumUserinfoService;
import com.etone.smartAudit.domain.AdminRole;
import com.etone.smartAudit.vo.PUumOrgVO;
import com.etone.smartFlow.domain.dto.FlowRoleDTO;
import com.etone.smartFlow.domain.vo.FlowRoleVo;
import com.etone.smartFlow.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SysRoleServiceImpl implements ISysRoleService {

    @Autowired
    private  CommPUumOrganizationinfoService organizationinfoService;
    @Override
    public List<FlowRoleVo> selectRoleList(FlowRoleDTO role) {

        List<PUumOrgVO> list = organizationinfoService.searchOrgs(role.getKey());
        List<FlowRoleVo> ovList = new ArrayList<>();
        list.stream().forEach(org -> {
            ovList.add(orgToFlowRoleVo(org));
        });

        return ovList;
    }


    private FlowRoleVo orgToFlowRoleVo(PUumOrgVO org){
        FlowRoleVo vo = new FlowRoleVo();
        vo.setName(org.getOUFullName());
        vo.setOuguId(org.getOUGUID());
        return vo;
    }

    @Override
    public FlowRoleVo selectRoleById(String roleId) {
        PUumOrgVO vo = organizationinfoService.getOrgById(roleId);
        return orgToFlowRoleVo(vo);
    }

    @Override
    public List<FlowRoleVo> selectRoleAll() {
        List<PUumOrgVO> list =organizationinfoService.getAll();
        List<FlowRoleVo> ovList = new ArrayList<>();
        list.stream().forEach(org -> {
            ovList.add(orgToFlowRoleVo(org));
        });
        return ovList;
    }
}
